package com.mushuilingfeng.ddd.user.api;

import cn.hutool.core.bean.BeanUtil;
import com.mushuilingfeng.ddd.user.cover.IDataCover;
import com.mushuilingfeng.ddd.user.domain.base.BusinessException;
import com.mushuilingfeng.ddd.user.domain.base.Ii8nCode;
import com.mushuilingfeng.ddd.user.sdk.api.TokenApi;
import com.mushuilingfeng.ddd.user.sdk.modle.User;
import com.mushuilingfeng.ddd.user.service.ITokenService;
import com.mushuilingfeng.ddd.user.vo.UserVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 沐水淋风
 * @date 2024/10/13
 */
@RestController
@AllArgsConstructor
@Tag(name = "TokenApi")
public class TokenApiImpl implements TokenApi {
    private final ITokenService tokenService;
    
    @Override
    public User getUser(String token) {
        com.mushuilingfeng.ddd.user.domain.user.entity.User user = tokenService.getUserByToken(token);
        if (null == user) {
            throw new BusinessException(Ii8nCode.PARAM_INVALID);
        }
        UserVO userVO = IDataCover.INSTANCE.toUserVO(user);
        User restUser = new User();
        BeanUtil.copyProperties(userVO, restUser);
        return restUser;
    }
    
    
}
